<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html><html lang="en">
	<head>
		<!--加载header文件-->
		<?php
		include_once 'public/views/header.php';
		?>
		<link rel="stylesheet" href="public/css/edit.css" />
		<script src="public/xr/xrDatatable.js"></script>	
        <script src="public/home/js/function.js"></script>
		<script src="public/js/list.js"></script>
	</head>
	<style >
		th,td{
			text-align: center!important;
		}
		.index-b{
	   		border-radius:10px; height:16px;  padding:0px 5px 0px 5px; line-height:16px; display:inline-block;  color:white; background-color:#44C678; font-size:10px;
	   	}
	   	body{
		    background-color: white!important;
		}
		.xrTable tbody tr td a {
			margin-left: 0;
		}
	</style>
	<body>		
		<div class="container">
			<div class="row">
				<input type="hidden" id="modal_title" value="<?=$title ?>" />
				<input type="hidden" id='url' value="<?php echo base_url()?>">
				<input type="hidden" id="modal_height" value="450" />
				<input type="hidden" name="select" id="select" value="<?=$params['select'] ?>"/>
				<input type="hidden" name="type" id="type" value="<?=$params['type'] ?>"/>
				<input type="hidden" name="course_units"id="course_units" value="<?=$params['course_units'] ?>"/>
				<input type="hidden" name="listen_type"id="listen_type" value="<?=$params['listen_type'] ?>"/>
				<input type="hidden" name="start_time" id="start_time" value="<?=$params['start_time'] ?>"/>
				<input type="hidden" name="end_time" id="end_time" value="<?=$params['end_time'] ?>"/>
				<input type="hidden" name="source" id="source" value="<?=$params['source'] ?>"/>
				<form id="editForm">
				<table class='edit_table'>
					<?php if(isset($newlist)):?>
					<tr>
						<th style="height:30px;">授课教师</th>
						<th>分数</th>
						<th>听课教师</th>
						<th>平均分</th>
					</tr>	
					<?php $key=0; 
					foreach ($newlist as $k => $v){
						foreach ($v as $k1 => $v1) {
							$key++;
							if($k1==0){
								echo "<tr><td rowspan='".count($v)."'>".$v1['teacher_name']."(".$v1['teacher_code'].")</td><td>".$v1['score']."</td><td><a href='javascript:(1);' onclick='getHerf(this);' listen_name='".$v1['listen_name']."' listen_code='".$v1['listen_code']."'>".$v1['listen_name']."</a></td><td rowspan='".count($v)."'>".sprintf("%.2f",array_sum(array_column($v,'score'))/count($v))."</td></tr>";
							}else{
									echo " <tr><td>".$v1['score']."</td><td><a href='javascript:(1);' onclick='getHerf(this);' listen_name='".$v1['listen_name']."' listen_code='".$v1['listen_code']."'>".$v1['listen_name']."</a></td></tr>";
							}
							// if($k1==0){
							// 	echo "<tr><td rowspan='".count($v)."'>".$v1['listen_name']."(".$v1['listen_code'].")</td><td>".$v1['score']."</td><td rowspan='".count($v)."'>".sprintf("%.2f",array_sum(array_column($v,'score'))/count($v))."</td></tr>";
							// }else{
							// 	echo " <tr><td>".$v1['score']."</td></tr>";
							// }
						}
					}?>	
					<?php else:?>
						<tr>
							<th style="height:30px;">序号</th>
							<th style="height:30px;">工号</th>
							<th>姓名</th>
							<th>总分</th>
						</tr>
						<?php foreach ($list as $k => $v):?>					
							<tr>
								<td><b class="index-b"><?php echo $k+1 ?></b></td>
								<td><?php echo $v['teacher_code'] ?></td>
								<td><?php echo $v['listen_name'] ?></td>
								<td><?php echo $v['score'] ?></td>
							</tr>
						<?php endforeach ?>
					<?php endif?>
					
			</form>
	
				
			</div>
		</div>
	</body>	
<script>

		$(function() {
			addDialogButton("导出",exports);
		});

		var exports = function() {
			var data = getFormJson();
			data.select = $("#select").val();
			data.type = $("#type").val();
			data.listen_type = $("#listen_type").val();
			data.course_units = $("#course_units").val();
			data.start_time = $("#start_time").val();
			data.end_time = $("#end_time").val();

			var	source = $("#source").val(); 
			if(source == 'Attended'){
				var url = "Admin/StatisticsAttended/getTeacherList/1/1/1/1/1/1/true";
			}else if(source == 'AttendDept'){
				var url = "Admin/StatisticsAttendDept/getTeacherList/1/1/1/1/1/1/1/true";
			}
			//	console.log(data);

			var msg = "请确认是否导出?";
		    swal({
		        title: "请确认",
		        text: msg,
		        type: "warning",
		        showCancelButton: true,
		        closeOnConfirm: true,
		        confirmButtonText: "确定",
		        cancelButtonText: '取消',
		        confirmButtonColor: "#ec6c62"
		    }, function(isConfirm) {
		        if(isConfirm) {
		            $.ajax({
		                type: "post",
		                url: url,
		                data:data,
		                async: true,
		                dataType:'json',
		                success: function(data) {
		                    if(data.status) {
		                        location.href=getRootPath()+'/'+data.v;
		                    } else {
		                        window.parent.topMessagePrompt('error',ret.msg);
		                    }
		                }
		            });
		        }
		    });
		}

		//查看听课统计报表
		function getHerf(obj){
				var listen_code=encodeURIComponent($(obj).attr('listen_code'));
				//var listen_name=encodeURIComponent($(obj).attr('listen_name'));
			// console.log(listen_name);
             var url= $("#url").val()+'Admin/StatisticsAttend/Index/'+listen_code;
			showDialogModal(url,900,600);
		}

	</script>
</html>
